package hrms.util;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogUtil {
	public static void saveEx(Exception e){
		try {
			FileWriter fw = new FileWriter("E:/HRMS_error.log",true);
			PrintWriter pw = new PrintWriter(fw);
			Date time = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
			String timeStr = sdf.format(time);
			pw.println("*******************************************************************************************************************");
			pw.println("*异常类型:"+e);
			pw.println("*异常时间:"+timeStr);
			pw.println("*********************异常详细信息***********************************************************************************");
			e.printStackTrace(pw);
			pw.close();
			fw.close();
			System.out.println("Had writen an error log !");
		} catch (Exception ex) {
			throw new RuntimeException("记录异常失败");
		}
	}
}
